#!/bin/sh
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/sys_check.sh"
source ${LMD_BASE_INSTALL_SCRIPT_DIR}/global/alias.sh

export CURRENT_APP_PATH=${LMD_APPS_DIR}/ComfyUI
echo 'App Dir: '${CURRENT_APP_PATH}

cd $CURRENT_APP_PATH
python --version
pip --version

START_PARAMS=""
if [ -f /etc/os-release ]; then
    echo "Linux"
elif [ -f /System/Library/CoreServices/SystemVersion.plist ]; then
    echo "macOS"
    ARCH=$(uname -m)
    CONDA_INSTALL_SCRIPT_URL=$(uname -m)
    if [ "$ARCH" == "x86_64" ]; then
        START_PARAMS="--disable-cuda-malloc --use-split-cross-attention --cpu"
    elif [ "$ARCH" == "arm64" ]; then
        START_PARAMS=""
    fi
elif current_os_is_windows; then
    echo "Windows"
    gpu_info=$(cmd //c "wmic path win32_VideoController get name")
    echo "$gpu_info"
    if echo "$gpu_info" | grep -i "nvidia" > /dev/null; then
        echo "NVIDIA Graphics Card detected."
        START_PARAMS=""
    else
        echo "No NVIDIA graphics card detected"
        START_PARAMS="--disable-cuda-malloc --use-split-cross-attention --cpu"
    fi
else
    echo "Unknown OS"
fi
python main.py $START_PARAMS
